#include <bits/stdc++.h>
#define F(i, n) for(int i = 1; i <= n; i++)

using namespace std;

const int N = 10;
int n, a = 1, b = 1, c = 1;
int dp[N][N][N][N];//x1, y1, x2, y2
int board[N][N];

int main() {
    cin >> n;
    while (true) {
        cin >> a >> b >> c;
        if (!a && !b && !c) {
            break;
        }
        else {
            board[a][b] = c;
        }
    }
    F(i, n) {
        F(j, n) {
            F(k, n) {
                F(l, n) {
                    dp[i][j][k][l] = max({dp[i - 1][j][k - 1][l],
                                       dp[i - 1][j][k][l - 1],
                                       dp[i][j - 1][k - 1][l],
                                       dp[i][j - 1][k][l - 1]}) +
                                       board[i][j] +
                                       board[k][l];
                    if (i == k && j == l) {
                        dp[i][j][k][l] -= board[i][j];
                    }
                }
            }
        }
    }

    cout << dp[n][n][n][n];
}